# Maintainer: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
# Contributor: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
pkgname=kicad
pkgver=7.0.10
pkgrel=0
pkgdesc="Cross Platform and Open Source Electronics Design Automation Suite"
url="https://www.kicad.org/"
# No support for s390x/riscv64 in libcontext (shipped with kicad)
# 32-bit arm: memory alignment access error in tests
arch="all !armhf !armv7 !riscv64 !s390x"
license="GPL-3.0-or-later"
makedepends="
	boost-dev
	cairo-dev
	chrpath
	cmake
	curl-dev
	glew-dev
	glm-dev
	ngspice-dev
	opencascade-dev
	py3-wxpython
	python3-dev
	samurai
	swig
	unixodbc-dev
	wxwidgets-dev
	zlib-dev
	"
depends="python3"
subpackages="$pkgname-doc"
source="
	https://gitlab.com/kicad/code/kicad/-/archive/$pkgver/kicad-$pkgver.tar.gz
	"

provides="$pkgname-opencascade=$pkgver-r$pkgrel"
replaces="$pkgname-opencascade"

build() {
	# XXX: GLIBCXX_ASSERTIONS causes link errors and symbols are missing
	# -DKICAD_STDLIB_LIGHT_DEBUG also enables this, maybe that works instead
	CFLAGS="$CFLAGS -O2" \
	CXXFLAGS="$CXXFLAGS -U_GLIBCXX_ASSERTIONS -O2" \
	cmake -B build -G Ninja -Wno-dev \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DKICAD_USE_EGL=ON \
		-DKICAD_SCRIPTING_WXPYTHON=ON \
		-DKICAD_USE_BUNDLED_GLEW=ON
	# build order workaround
	cmake --build build --target common/pcb_lexer.h
	cmake --build build
}

check() {
	ctest --test-dir build --output-on-failure \
		-E '(qa_eeschema|qa_common|qa_pcbnew)'
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	local sitedir=$(python3 -c "import site; print(site.getsitepackages()[0])")
	chrpath -d "$pkgdir/$sitedir"/_pcbnew.so
}

doc() {
	default_doc

	amove usr/share/kicad/demos
}

sha512sums="
4ac01b66bd61ba85f9b02da71eeb985f0780a972b18ab842a6d7f16404b919ed6bc1c3ba3a6452f543cb1995b1feec4f68ca908cd81f9bbff9e8aa09ce0e5666  kicad-7.0.10.tar.gz
"
